/*
 * Copyright 2008-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ssn.common.print;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import ssn.common.util.DateUtil;
import ssn.common.web.CommonController;
import ssn.currentsystem.service.CurrentSystemService;
import ssn.currentsystem.vo.CurrentSystemVO;
import ssn.daily.service.DailyService;
import ssn.daily.vo.DailyVO;
import egovframework.rte.fdl.cmmn.exception.EgovBizException;
import egovframework.rte.fdl.string.EgovStringUtil;


/**  
 * @Class Name : 
 * @
 * @  수정일      수정자              수정내용
 * @ ---------   ---------   -------------------------------
 * @ 2013.11.02           최초생성
 * 
 * @see
 */
@Controller
public class PrintController extends CommonController{
	
    @Resource(name = "dailyService")
    private DailyService dailyService;
    
    @Resource(name = "currentSystemService")
    private CurrentSystemService currentSystemService;
    
    /**
     * common print
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/common/printView.do")
    public String dailyPrintView(ModelMap model) throws Exception {
    	return "/common/printView";
    }
    
    /**
     * print daily
     * @param dailyVO
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/common/dailyPrintView.do")
    public String dailyPrintView(@ModelAttribute("dailyVO") DailyVO dailyVO,
    			ModelMap model) throws Exception {
    	
    	if(EgovStringUtil.isEmpty(dailyVO.getSdl_dlog_key())){
    		throw new EgovBizException(propertiesService.getString("info.nodata.msg"));
    	}
    	DailyVO resultVO = dailyService.selectDailyLog(dailyVO);
    	model.addAttribute("dateAsString", DateUtil.getDayOfAsString(resultVO.getSdl_daily_date()));
    	model.addAttribute("weekAsString", DateUtil.getDayOfWeekAsString(resultVO.getSdl_daily_date()));
    	model.addAttribute("resultVO", resultVO);
        return "/common/dailyPrintView";
    }
    
    /**
     * 시설현황 이력 프린트 페이지
     * @param currentSystemVO
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping(value="/common/csRecordPrintView.do")
    public String currentSystemRecordView(@ModelAttribute("currentSystemVO") CurrentSystemVO currentSystemVO,
    		ModelMap model) throws Exception {
    	
    	if(EgovStringUtil.isEmpty(currentSystemVO.getScs_sys_key())){
    		throw new EgovBizException(propertiesService.getString("info.nodata.msg"));
    	}
    	CurrentSystemVO resultVO = currentSystemService.selectCurrentSystemInfo(currentSystemVO);
    	
    	model.addAttribute("resultVO", resultVO);
    	return "/common/csRecordPrintView";
    }
}
